﻿<%@ Page Title="" Language="C#" MasterPageFile="~/masterpagecuatui.Master" AutoEventWireup="true" CodeBehind="Personal.aspx.cs" Inherits="SQT.tracnghiem.Personal" %>

<%@ Import Namespace="DataAccess" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="Content/css/staffpersonal.css" rel="stylesheet" />
    <script src="../Scripts/Personal.js"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <%try
      { %>
    <div id="main" class="w3-row">
        <div class="w3-content">
            <div class="w3-card-4">
                <div class="user-wall-paper w3-row w3-display-container" style="background: url('/Content/wallpaper/<%=this.banner%>') no-repeat center; background-size: 100%">
                    <div class="w3-col" style="width: 20%">
                        <div class="w3-display-container user-img-box">
                            <img src="../Content/Avatar/<%=avatar%>" class="user-img" />
                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {%>
                            <div style="cursor: pointer" onclick="document.getElementById('doiavatar').style.display = 'block'" class="change-user-avatar-btn w3-padding w3-display-bottommiddle black-opacity-bg"><i class="fa fa-camera"></i>&nbsp;Đổi ảnh đại diện</div>
                            <%} %>
                        </div>
                    </div>
                    <div class="w3-col l5 w3-text-white">
                        <span class="w3-xlarge black-opacity-bg"><%=fullname%></span><br />
                        <span class="w3-large black-opacity-bg"><%=email%></span><br />
                        <span class="w3-large black-opacity-bg"><%if (this.sex == 1)
                                                                  { %>Nam<%}
                                                                  else
                                                                  { %>Nữ<%} %>, <%=this.old%> tuổi, <%=this.address%></span>
                        <%--<p class="black-opacity-bg">Tính cách nói nhiều, điên điên, hiền, nhây, lầy lội,...</p>--%>
                    </div>
                    <%if (this.user.ToString() == Session["user_id"].ToString())
                      {%>
                    <div data-toggle="tooltip" data-placement="right" title="Ảnh bìa sẽ đẹp hơn với kích thước 1140 x 250 pixel" onclick="document.getElementById('doianhbia').style.display = 'block'" onmouseover="$(this).addClass('black-opacity-bg')" onmouseout="$(this).removeClass('black-opacity-bg')" class="change-wall-paper-btn w3-text-white w3-display-topleft w3-padding">
                        <i class="fa fa-camera"></i>&nbsp;<div class="change-wall-paper-text">Cập nhật ảnh bìa</div>
                    </div>
                    <%} %>
                </div>
                <div class="w3-row">
                    <ul class="user-option-tab w3-navbar w3-light-grey w3-border-left w3-border-bottom w3-border-right">
                        <li class="w3-border-right"><a href="javascript:;" class="tablink w3-hover-teal w3-teal" onclick="openuser(event, 'ttcn');">Thông tin cá nhân</a></li>
                        <%
          if (this.user.ToString() == Session["user_id"].ToString())
          {%>
                        <li class="w3-border-right"><a href="javascript:;" class="tablink w3-hover-teal" onclick="openuser(event, 'bmtk');">Bảo mật tài khoản</a></li>
                        <%} %>
                        <li class="w3-border-right"><a href="javascript:;" class="tablink w3-hover-teal" onclick="openuser(event, 'kqlb');">Bài làm gần đây</a></li>
                    </ul>
                    <div id="ttcn" class="city w3-padding w3-border-left w3-border-bottom w3-border-right">
                        <header class="w3-row w3-border-bottom w3-border-teal w3-padding w3-text-teal w3-margin-bottom">
                            <label>Thông tin cơ bản</label>
                        </header>
                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Họ tên</label>
                            <%
          if (this.user.ToString() == Session["user_id"].ToString())
          {%>
                            <input type="text" id="personal_fullname" value="<%=fullname%>" placeholder="Nhập họ tên của bạn" />
                            <%}
                                else
                                { %>
                            <label><%=fullname%></label>
                            <%} %>
                            <label class="w3-hide w3-text-red" id="error_mes_name"></label>
                        </div>
                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Giới tính</label>
                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {%>
                            <div class="radio">
                                <%if (this.sex == 1)
                                  { %>
                                <input type="radio" name="user-sex" value="1" checked="checked" id="user-male" /><label for="user-male">Nam</label>&nbsp;
                        <input type="radio" name="user-sex" value="0" id="user-female" /><label for="user-female">Nữ</label>
                                <%}
                                  else
                                  { %>
                                <input type="radio" name="user-sex" value="1" id="user-male" /><label for="user-male">Nam</label>&nbsp;
                        <input type="radio" name="user-sex" value="0" checked="checked" id="user-female" /><label for="user-female">Nữ</label>
                                <%}%>
                            </div>
                            <%}
                              else
                              {
                                  if (sex == 1)
                                  {%>
                            <label>Nam</label><%}
                                  else
                                  { %>
                            <label>Nữ</label>
                            <%} %>
                            <%} %>
                        </div>
                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Sinh nhật</label>
                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {%>
                            <div class="w3-col l1 w3-padding-right">
                                <select id="personal_day">
                                    <%for (int i = 1; i <= 31; i++)
                                      {
                                          if (i == this.day)
                                          {%>
                                    <option selected="selected" value="<%=i %>"><%=i %></option>
                                    <%}
                                          else
                                          { %>
                                    <option value="<%=i %>"><%=i %></option>
                                    <%} %>
                                    <%} %>
                                </select>
                            </div>
                            <div class="w3-col l1 w3-padding-right">
                                <select id="personal_month">
                                    <%for (int i = 1; i <= 12; i++)
                                      {
                                          if (i == this.month)
                                          { %>
                                    <option selected="selected" value="<%=i %>"><%=i %></option>
                                    <%}
                                          else
                                          { %>
                                    <option value="<%=i %>"><%=i %></option>
                                    <%} %>
                                    <%} %>
                                </select>
                            </div>
                            <div class="w3-col l2 w3-padding-right">
                                <select id="personal_year">
                                    <%
                                  for (int i = (int)get_year; i >= get_year - 40; i--)
                                  {
                                      if (i == this.year)
                                      { %>
                                    <option selected="selected" value="<%=i %>"><%=i %></option>
                                    <%}
                                      else
                                      { %>
                                    <option value="<%=i %>"><%=i %></option>
                                    <%} %>
                                    <%} %>
                                </select>
                            </div>
                            <%}
                              else
                              { %>
                            <label><%=day %>/<%=month %>/<%=year %></label>
                            <%} %>
                        </div>
                        <%--<div class="w3-row w3-padding">
                            <label class="w3-col l2">Giới thiệu</label><textarea rows="3" placeholder="Ví dụ: Tính cách khùng khùng..."></textarea>
                        </div>--%>
                        <header class="w3-row w3-border-bottom w3-border-teal w3-padding w3-text-teal w3-margin-bottom">
                            <label>Thông tin liên hệ</label>
                        </header>

                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Email</label>
                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {%>
                            <input type="email" id="personal_email" value="<%=email %>" placeholder="Nhập email của bạn" />
                            <label class="w3-hide w3-text-red" id="error_mes_email"></label>
                            <%}
                              else
                              { %>
                            <label><%=email %></label>
                            <%} %>
                        </div>



                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Số điện thoại</label>

                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {%>
                            <input type="text" id="personal_phone" value="<%=phone %>" placeholder="Nhập số điện thoại của bạn" />
                            <%}
                              else
                              { %>
                            <label><%=phone %></label>
                            <%} %>
                        </div>

                        <div class="w3-row w3-padding">
                            <label class="w3-col l2">Địa chỉ</label>
                            <%if (this.user.ToString() == Session["user_id"].ToString())
                              {
                                  var get_province = (from p in new TblProvinceController().FetchAll() orderby p.ProvinceName descending select p);%>
                            <div class="w3-col l2 w3-padding-right">
                                <select id="personal_province">
                                    <%if (this.province == null)
                                      {
                                    %>
                                    <option selected="selected" value="0">Tỉnh</option>
                                    <%
                                          foreach (TblProvince province in get_province)
                                          {
                                    %>
                                    <option value="<%=province.Id%>"><%=province.ProvinceName%></option>
                                    <%}
                                      }
                                      else
                                      {
                                          foreach (TblProvince province in get_province)
                                          {
                                              if (province.Id == this.province)
                                              {
                                    %>
                                    <option selected="selected" value="<%=province.Id%>"><%=province.ProvinceName%></option>
                                    <%}
                                              else
                                              { %>
                                    <option value="<%=province.Id%>"><%=province.ProvinceName%></option>
                                    <%} %>

                                    <%}
                                      } %>
                                </select>
                            </div>
                            <div class="w3-col l2 w3-padding-right">
                                <select id="personal_city">
                                    <%
                                  if (this.city != null)
                                  {
                                      foreach (TblCity city in (from p in new TblCityController().FetchAll().Where(x => x.ProvinceId == this.province) orderby p.CityName descending select p))
                                      {
                                          if (city.Id == this.city)
                                          {
                                    %>
                                    <option selected="selected" value="<%=city.Id%>"><%=city.CityName%></option>
                                    <%}
                                          else
                                          { %>
                                    <option value="<%=city.Id%>"><%=city.CityName%></option>
                                    <%} %>

                                    <%}
                                  } %>
                                </select>
                            </div>
                            <%}
                              else
                              { %>
                            <label><%=address %></label>
                            <%} %>
                        </div>

                        <%if (this.user.ToString() == Session["user_id"].ToString())
                          {%>
                        <div class="w3-row w3-padding w3-margin-top">
                            <a id="btn_edit_info" class="w3-btn w3-teal"><i class="fa fa-edit"></i>&nbsp;Lưu thay đổi</a>
                        </div>
                        <%} %>
                    </div>
                    <%
          var get_result = (from p in new TblResultController().FetchAll() orderby p.ResultId descending where p.ResultUser == this.user select p).Take(10).ToList();
                    %>
                    <div id="kqlb" class="city w3-border-left w3-border-bottom w3-border-right" style="display: none">
                        <table class="w3-table w3-striped w3-bordered">
                            <tr class="w3-teal">
                                <th>Tên bài</th>
                                <th>Ngày làm</th>
                                <th>Thời gian</th>
                                <th>Hoàn thành</th>
                                <th>Từ vựng</th>
                                <th>Ngữ pháp</th>
                                <th>Nghe</th>
                                <th>Hán tự</th>
                                <th>Tổng điểm</th>
                            </tr>
                            <%if (get_result.Count != 0)
                              {
                                  for (int i = 0; i < get_result.Count; i++)
                                  {
                                      var get_test = new TblTestController().FetchAll().Where(x => x.TestId == get_result[0].TestId).Single();
                                      string result_user = get_result[i].ResultAnswer;
                                      int tuvung = 0, nguphap = 0, nghe = 0, hantu = 0;

                                      var get_tuvung = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 1).ToList();
                                      var get_nguphap = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 2).ToList();
                                      var get_nghe = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 3).ToList();
                                      var get_hantu = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId && x.TestDetailType == 4).ToList();
                                      int td_count = new TblTestDetailController().FetchAll().Where(x => x.TestId == get_test.TestId).ToList().Count;
                                      float score = 100f / td_count;
                                      string[] split = new string[result_user.Split(',').Length];
                                      string[] split2 = new string[2];
                                      split = result_user.Split(',');
                                      for (int j = 0; j < result_user.Split(',').Length - 1; j++)
                                      {
                                          split2 = split[j].Split('-');
                                          int ok = 0;
                                          var get_td = new TblTestDetailController().FetchAll().Where(x => x.TestDetailId == int.Parse(split2[0])).Single();
                                          if (get_td.TestDetailConfirm == int.Parse(split2[1]))
                                              ok = 1;
                                          if (ok == 1)
                                          {
                                              if (get_td.TestDetailType == 1)
                                                  tuvung++;
                                              else if (get_td.TestDetailType == 2)
                                                  nguphap++;
                                              else if (get_td.TestDetailType == 3)
                                                  nghe++;
                                              else if (get_td.TestDetailType == 4)
                                                  hantu++;
                                          }
                                      }
                                      score = score * (tuvung + nguphap + nghe + hantu);
                                      
                            %>
                            <tr>
                                <td><%=get_test.TestTitle %></td>
                                <td><%=DateTime.Parse(get_result[i].ResultDate.ToString()).Day %>/<%=DateTime.Parse(get_result[i].ResultDate.ToString()).Month %>/<%=DateTime.Parse(get_result[i].ResultDate.ToString()).Year %></td>
                                <td><%=get_test.TestTime %> phút</td>
                                <td><%=get_result[i].ResultTime %> phút</td>
                                <td><%=tuvung %>/<%=get_tuvung.Count %> câu</td>
                                <td><%=nguphap %>/<%=get_nguphap.Count %> câu</td>
                                <td><%=nghe %>/<%=get_nghe.Count %> câu</td>
                                <td><%=hantu %>/<%=get_hantu.Count %> câu</td>
                                <td><%=float.Parse(String.Format("{0:00.0}", score)) %></td>
                            </tr>
                            <%}
                              }
                              else
                              { %>
                            <tr>
                                <td colspan="9" class="w3-center">Bạn chưa hoàn thành bài trắc nghiệm nào!</td>
                            </tr>
                            <%} %>
                        </table>
                    </div>

                    <div id="bmtk" style="display:none" class="city w3-padding w3-border-left w3-border-bottom w3-border-right">
                        <header class="w3-row w3-border-bottom w3-border-teal w3-padding w3-text-teal w3-margin-bottom">
                            <label>Thay đổi mật khẩu</label>
                        </header>
                        <div id="change_pass">
                            <div class="w3-row">
                                <p id="messenge_pass" class="w3-text-red"></p>
                            </div>
                            <div class="w3-row w3-padding">
                                <label class="w3-col l2">Mật khẩu hiện tại</label>
                                <input id="txt_oldpass" type="password" placeholder="Nhập mật khẩu hiện tại" />
                            </div>
                            <div class="w3-row w3-padding">
                                <label class="w3-col l2">Mật khẩu mới</label>
                                <input id="txt_newpass" type="password" placeholder="Nhập mật khẩu mới" />
                            </div>
                            <div class="w3-row w3-padding">
                                <label class="w3-col l2">Nhập lại mật khẩu mới</label>
                                <input id="txt_repass" type="password" placeholder="Nhập lại mật khẩu mới" />
                            </div>
                        </div>
                        <div class="w3-row w3-padding">
                            <a id="btn_change_pass" class="w3-btn w3-teal"><i class="fa fa-check"></i>&nbsp;Xác nhận</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="doiavatar" class="w3-modal">
        <div class="w3-modal-content w3-center w3-animate-top w3-card-8 w3-white" style="width: 40%">
            <header class="w3-padding">
                <p class="w3-xlarge">Cập nhật ảnh đại diện</p>
            </header>
            <div class="w3-row w3-center">
                <input type="file" role="file" class="changewallpaper" name="fileUpload" id="changeavatar" />
                <label for="changeavatar" class="w3-btn w3-border w3-white"><i class="fa fa-camera"></i>&nbsp;Chọn ảnh đại diện</label>
            </div>
            <div class="w3-row w3-padding">
                <img id="avatar" src="../Content/avatar/<%=avatar%>" class="user-img-box" />
            </div>
            <div class="w3-row w3-padding">
                <a id="btn_edit_avatar" class="w3-btn w3-white w3-border w3-border-black"><i class="fa fa-refresh"></i>&nbsp;Cập nhật</a>
                <a onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-btn w3-white w3-border w3-border-black"><i class="fa fa-times"></i>&nbsp;Hủy</a>
            </div>
        </div>
    </div>
    <div id="doianhbia" class="w3-modal">
        <div class="w3-modal-content w3-center w3-animate-top w3-card-8 w3-white">
            <header class="w3-padding">
                <p class="w3-xlarge">Cập nhật ảnh bìa</p>
            </header>
            <div class="w3-row w3-center">
                <input type="file" role="file" class="changewallpaper" name="fileUpload" id="changewallpaper" />
                <label for="changewallpaper" class="w3-btn w3-border w3-white"><i class="fa fa-camera"></i>&nbsp;Chọn ảnh bìa</label>
            </div>
            <div class="w3-row w3-padding">
                <img id="wallpaper" src="../Content/wallpaper/<%=banner %>" class="wallpaper-box" />
            </div>
            <div class="w3-row w3-padding">
                <a id="btn_edit_wall" class="w3-btn w3-white w3-border w3-border-black"><i class="fa fa-refresh"></i>&nbsp;Cập nhật</a>
                <a onclick="this.parentElement.parentElement.parentElement.style.display='none'" class="w3-btn w3-white w3-border w3-border-black"><i class="fa fa-times"></i>&nbsp;Hủy</a>
            </div>
        </div>
    </div>
    <script>
        function openuser(evt, cityName) {
            var i, x, tablinks;
            x = document.getElementsByClassName("city");
            for (i = 0; i < x.length; i++) {
                x[i].style.display = "none";
            }
            tablinks = document.getElementsByClassName("tablink");
            for (i = 0; i < x.length; i++) {
                tablinks[i].className = tablinks[i].className.replace(" w3-teal", "");
            }
            document.getElementById(cityName).style.display = "block";
            evt.currentTarget.className += " w3-teal";
        }
    </script>
    <%}
      catch { Response.Redirect("~/trang-chu"); } %>
</asp:Content>
